package com.aaa.controller.scl;

import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.fpa.TestPlanFpa;
import com.aaa.entity.scl.TestPlanScl;
import com.aaa.service.scl.TestPlanSclService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * 测试计划fpa(TestPlanScl)表控制层
 *
 * @author makejava
 * @since 2022-08-31 20:35:38
 */
@RestController
@RequestMapping("testPlanScl")
public class TestPlanSclController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanSclService testPlanSclService;

    //分页查询
    @RequestMapping(value = "queryByPage.do", method = RequestMethod.GET)
    public Result queryAllUserPage(PageSortEntity pageSortEntity, TestPlanScl testPlanScl) {
        Page page = testPlanSclService.queryAll(pageSortEntity, testPlanScl);
        return success(page.getResult(), page.getTotal());
    }

    //添加
    @LogMonitor
    @PostMapping("insert.do")
    public Result add(TestPlanScl testPlanScl) {
        TestPlanScl insert = this.testPlanSclService.insert(testPlanScl);
        return success(insert);
    }

    //修改
    @LogMonitor
    @RequestMapping("/update.do")
    @ResponseBody
    public Result update(TestPlanScl testPlanScl) {
        boolean update = this.testPlanSclService.update(testPlanScl);
        if (update) {
            return success();
        } else {
            return fail();
        }
    }

    //删除
    @LogMonitor
    @RequestMapping("/delete.do")
    @ResponseBody
    public Result delete(String[] ids) {
        List list = new ArrayList();
        for (String id : ids) {
            list.add(id);
        }
        boolean user1 = testPlanSclService.deleteById(list);
        if (user1) {
            return success();
        } else {
            return fail();
        }
    }

    //添加时查询是否重名
    @GetMapping("repetitionName.do")
    public Result repetitionName(TestPlanScl testPlanScl) {
        boolean b = this.testPlanSclService.repetitionName(testPlanScl);
        if (b) {
            return success("测试名称可用");
        }
        return fail("测试名称重复，不可用");
    }


}

